﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using devtm.Collections;
using System.IO;
using devtm.Exceptions;

namespace devtm.Types.LazyLoading
{
    public class Directory : TableCollection<FileItem, string>
    {

        private ClsGetTypes dirroot;
        public Directory(DirectoryInfo dir, ClsGetTypes dirroot)
            : base(c => c.ItemFile.FullName)
        {
            DirectoryItem = dir;
            this.dirroot = dirroot;
        }

        public DirectoryInfo DirectoryItem { get; private set; }

        public string Name { get { return DirectoryItem.Name; } }
        public string FullName { get { return DirectoryItem.FullName; } }

        internal FileItem Add(FileInfo file)
        {

            FileItem f = new FileItem(file );

            this.Add(f);

            return f;

        }

        internal void RefrehFile()
        {

            ListException listeErreur = null;

            foreach (FileInfo file in DirectoryItem.GetFiles("*.dll"))
            {
                if (!ContainsKey(file.FullName))
                {

                    if (stLDirectories.Assemblies.ContainsKey(file.FullName))
                        continue;

                    stLDirectories.Assemblies.Add(new Types.LazyLoading.AssemblyFileNamespace(file));

                }
            }
            if (listeErreur != null)
                throw listeErreur;
        }

        

        public IEnumerable<FileItem> GetFiles()
        {
            foreach (FileItem file in this)
                yield return file;
        }

        
    }
}
